{% extends 'product/base.html' %}

{% block main %}

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="/list1_1_1/" class="fruit">新鲜水果</a></li>
					<li><a href="/list2_1_1/" class="seafood">海鲜水产</a></li>
					<li><a href="/list3_1_1/" class="meet">猪牛羊肉</a></li>
					<li><a href="/list4_1_1/" class="egg">禽类蛋品</a></li>
					<li><a href="/list5_1_1/" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="/list6_1_1/" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="/">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">{{ product_type.type_name }}</a>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					{% for each in latest_products %}
					<li>
						<a href="/{{ each.id }}/"><img src="/static/{{ each.product_img }}"></a>
						<h4><a href="/{{ each.id }}/">{{ each.product_name }}</a></h4>
						<div class="prize">￥{{ each.product_price }}</div>
					</li>
					{% endfor %}
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<div class="sort_bar">
				<a href="/list{{ product_type.id }}_1_1/"
				   {% if sort == "1" %}
				   class="active"
				   {% endif %}
				>默认</a>
				<a href="/list{{ product_type.id }}_1_2/"
				   {% if sort == "2" %}
				   class="active"
				   {% endif %}
				>价格</a>
				<a href="/list{{ product_type.id }}_1_3/"
				   {% if sort == "3" %}
				   class="active"
				   {% endif %}
				>人气</a>
			</div>

			<ul class="goods_type_list clearfix">
				{% for each in page %}
				<li>
					<a href="/{{ each.id }}/"><img src="/static/{{ each.product_img }}"></a>
					<h4><a href="/{{ each.id }}/">{{ each.product_name }}</a></h4>
					<div class="operate">
						<span class="prize">￥{{ each.product_price }}</span>
						<span class="unit">{{ each.product_unit }}</span>
						<a href="javascript:;" class="add_goods" id="{{ each.id }}" title="加入购物车"></a>
					</div>
				</li>
				{% endfor %}
			</ul>

			<div class="pagenation">
				{% if page.has_previous %}
				<a href="/list{{ product_type.id }}_{{ page.previous_page_number }}_{{ sort }}/"><上一页</a>
				{% endif %}

				{% for each in paginator.page_range %}
				{% if each == page.number %}
				<a href="#" class="active">{{ each }}</a>
				{% else %}
				<a href="/list{{ product_type.id }}_{{ each }}_{{ sort }}/">{{ each }}</a>
				{% endif %}
				{% endfor %}

				{% if page.has_next %}
				<a href="/list{{ product_type.id }}_{{ page.next_page_number }}_{{ sort }}/">下一页></a>
				{% endif %}
			</div>
		</div>
	</div>

{% endblock main %}

{% block script %}
<script type="text/javascript">
	$('.add_goods').click(function(){
		//判断是否登录，若未登录则先提示登录
		if($('.login_btn').text().indexOf('登录') >= 0){
			alert('请先登录后再进行购买！');
			location.href = '/user/login';
			return;
		}

		//ajax
		product_id = $(this).attr('id')
		$.get('/cart/add' + product_id +'_1/', function (data){
			$('#show_count').text(data.count);
		});
	})
</script>
{% endblock script %}